package com.ctsi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctsi.common.util.Search;
import com.ctsi.core.common.util.StringUtil;
import com.ctsi.core.database.util.PageUtil;
import com.ctsi.system.entity.MaterialGroup;
import com.ctsi.system.mapper.MaterialGroupMapper;
import com.ctsi.system.service.IMaterialGroupService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 素材组表 服务实现类
 * </p>
 *
 * @version 1.0
 * @author: wang xiao xiang
 * @date: 2021/8/19 10:26
 */
@Service
public class MaterialGroupServiceImpl extends ServiceImpl<MaterialGroupMapper, MaterialGroup> implements IMaterialGroupService {

    @Override
    public IPage<MaterialGroup> listPage(Search search) {
        LambdaQueryWrapper<MaterialGroup> queryWrapper = new LambdaQueryWrapper<>();
        if (StringUtil.isNotBlank(search.getStartDate())) {
            queryWrapper.between(MaterialGroup::getCreateTime, search.getStartDate(), search.getEndDate());
        }
        if (StringUtil.isNotBlank(search.getKeyword())) {
            queryWrapper.like(MaterialGroup::getId, search.getKeyword());
        }
        queryWrapper.orderByDesc(MaterialGroup::getCreateTime);
        return this.baseMapper.selectPage(PageUtil.getPage(search), queryWrapper);
    }

    @Override
    public List<MaterialGroup> listByType(String type) {
        return this.list(Wrappers.<MaterialGroup>query().lambda()
                .eq(MaterialGroup::getType, type).orderByDesc(MaterialGroup::getId));
    }
}
